//
//  SNShadowView.m
//  project
//
//  Created by 黄建华 on 2017/12/8.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "SNShadowView.h"

@implementation SNShadowView

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _type = 0;
        [self showWithType:_type];
    }
    return self;
}

- (void)createChartViewNormal {
    self.backgroundColor     = [UIColor whiteColor];
    self.layer.shadowOpacity = 0.95f;
    self.layer.shadowColor   = SNCOLORGRAYLINE.CGColor;
    self.layer.shadowRadius  = 4.f;
    self.layer.shadowOffset  = CGSizeMake(3, 3);
}

- (void)createChartViewOther
{
    self.backgroundColor     = [UIColor clearColor];
    if (_lineView)
    {
        [_lineView removeFromSuperview];
        _lineView = nil;
    }
    _lineView = [[UIView alloc]init];
    _lineView.frame = SNFRAME(0, 0, HHHWIDTH, 4);
    _lineView.backgroundColor = [UIColor whiteColor];
    _lineView.alpha = 0.9;
    [self addSubview:_lineView];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[ (__bridge id)SNCOLORGRAYLINE.CGColor,(__bridge id)SNCOLORGRAYLINE.CGColor, (__bridge id)[UIColor whiteColor].CGColor];
    gradientLayer.locations = @[@0.05,@0.2, @1.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0.0, 1.0);
    gradientLayer.frame = _lineView.frame;
    [_lineView.layer addSublayer:gradientLayer];
    
//    _lineView.alpha = 0.8;
//    self.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.layer.shadowOpacity = 0.95f;
//    self.layer.shadowRadius = 1.f;
//    self.layer.shadowOffset = CGSizeMake(1,1);
}

- (void)showWithType:(NSInteger)type
{
    if (type == 0)
    {
        [self createChartViewNormal];
    }
    else
    {
        [self createChartViewOther];
    }
}

@end

